package de.dopichaj.labrador.genetic;


import java.io.File;

import de.dopichaj.labrador.inex.assess.Assessable;
import de.dopichaj.labrador.search.hit.AbstractHit;
import de.dopichaj.labrador.search.hit.Hit;



public final class AssessedHit extends AbstractHit implements Assessable {
    
    private final Hit hit;
    private final double exh;
    private final double spec;
    private final int hashCache;
    private final float originalScore;
    
    public AssessedHit(Hit hit, double exh, double spec) {
        this.hit = hit;
        this.exh = exh;
        this.spec = spec;
        hashCache = hit.hashCode();
        originalScore = hit.getScore();
    }

    public int getContentLength() {
        return hit.getContentLength();
    }

    public int getDepth() {
        return hit.getDepth();
    }

    public String getEnclosingXPath() {
        return hit.getEnclosingXPath();
    }

    public File getFile() {
        return hit.getFile();
    }

    public String getMarkup() {
        return hit.getMarkup();
    }

    public int getPosition() {
        return hit.getPosition();
    }

    public float getScore() {
        return hit.getScore();
    }

    public String getXPath() {
        return hit.getXPath();
    }

    public String[] getXPathParts() {
        return hit.getXPathParts();
    }

    public void setScore(float score) {
        hit.setScore(score);
    }

    public double getSpecificity() {
        return spec;
    }
    
    public double getExhaustivity() {
        return exh;
    }
    
    public float getFactor() {
        return hit.getScore();
    }

    @Override
    public int hashCode() {
        return hashCache;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (!super.equals(obj))
            return false;
        if (getClass() != obj.getClass())
            return false;
        final AssessedHit other = (AssessedHit)obj;
        if (hit == null) {
            if (other.hit != null)
                return false;
        } else if (!hit.equals(other.hit))
            return false;
        return true;
    }

    public void resetScore() {
        hit.setScore(originalScore);
    }
    
    public boolean scoreHasChanged() {
        return Math.abs(hit.getScore() - originalScore) > 0.00001;
    }
}
/*
Copyright (c) 2007 Philipp Dopichaj

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/